<template>
  <!-- 出价 -->
  <el-dialog title="出价" v-model="editVisible" width="30%" draggable>
    <el-form ref="formRef" :model="form" label-width="150px" v-loading="loading">
      <el-row :gutter="10">
        <el-col :span="20">
          <el-form-item label="出价：" prop="real_price">
            <el-input v-model.trim="form.real_price" placeholder="请出价"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="editVisible = false">取 消</el-button>
        <el-button type="primary" :disabled="disabledbtn" @click="submitForm">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { useState } from "@/hooks/useState.ts";
import type { IRecycleOrderBid } from "@/types/recoveryManage/recycleOrder";
import { putRecycleOrderBidInfo } from "@/utils/api/recycleOrder";
const { disabledbtn, loading, toggleState } = useState();
const emit = defineEmits<{
  handleSuccess: [];
}>();
const editVisible = defineModel<boolean>("editVisible", { required: true });
const form = defineModel<IRecycleOrderBid>("form", { required: true });
/* 保存或编辑信息 */
function submitForm() {
  if (form.value.real_price === "") {
    ElMessage.warning("请填写估价");
    return;
  }
  toggleState(true);
  putRecycleOrderBidInfo(form.value)
    .then(res => {
      ElMessage.success(res.msg);
      editVisible.value = false;
      emit("handleSuccess");
    })
    .catch(() => {})
    .finally(() => {
      toggleState(false);
    });
}
</script>

<style lang="scss" scoped></style>
